home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: [Help] I can't find my error.
- Date: 22 Feb 96 15:44:38 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.825003878@rscernix>
- References: <4ggvgr$1b2@aurora.engr.LaTech.edu>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4ggvgr$1b2@aurora.engr.LaTech.edu> pluu@engr.LaTech.edu (PL) writes:
-
- >#include <stdio.h>
- >
- >main()
- >{
- > char name;
-
- This doesn't look like a declaration for an array of characters, does it?
-
- > int age, next_age;
- >
- > printf("%s\n","Please enter your name and age: ");
-
- Why not:
- printf("Please enter your name and age:\n");
-
- Or the nicer:
- printf("Please enter your name and age: ");
- fflush(stdout);
-
- > scanf("%s%d\n", &name, &age);
-
- Never assume that scanf always succeeds. Always check its return value,
- to see if the user hasn't typed some gibberish.
-
- %s in scanf is allowing the user to crash your program, if he types more
- characters than you're prepared to accept. Always use %NNs where NN
- stands for the size of the character array which will receive the input
- minus one.
-
- > next_age= age + 1;
- > printf("Hi, %s ,next year, you will be %d\n", name, next_age);
- >}
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-